package com.lz.sports.ui.group

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.lz.library.base.BaseFragment
import com.lz.library.extension.click
import com.lz.sports.BR
import com.lz.sports.R
import com.lz.sports.adapter.AssistGroupAdapter
import com.lz.sports.bean.DeviceInfo
import com.lz.sports.databinding.FragmAssistGroupBinding
import com.lz.sports.vm.group.AssistGroupViewModel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

/**
 * 辅助设备组编辑
 */
class AssistGroupFragment : BaseFragment<AssistGroupViewModel, FragmAssistGroupBinding>() {

    private val adapter by lazy { AssistGroupAdapter() }

    override fun getLayoutRes(): Int = R.layout.fragm_assist_group

    override fun getVMVariableId(): Int = BR.vm

    override fun initData(savedState: Bundle?) {
        binding.rvList.adapter = adapter
        val list = arguments!!.getParcelableArrayList<DeviceInfo>("assistDeviceInfoList")!!
        viewModel.deviceInfoList.value = list
        adapter.setNewData(list)

        lifecycleScope.launch {
            binding.tvConnect.click().collect { viewModel.connect() }}
    }

}